//
// Source code recreated from ConfigVo .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ht.modules.system.online.cgform.util;

import com.alibaba.fastjson2.JSONObject;
import java.math.BigDecimal;
import java.util.Map;
import com.ht.modules.system.online.cgform.entity.OnlCgformField;

public class OnlineDbHandler {
    public static final String NUM_TYPE_INT = "int";
    public static final String NUM_TYPE_INTEGER = "Integer";
    public static final String NUM_TYPE_DOUBLE = "double";
    public static final String NUM_TYPE_DECIMAL = "BigDecimal";
    public static final String DATE_TYPE = "Date";

    public OnlineDbHandler() {
    }

    public static boolean isNumField(String dbtype) {
        return "int".equals(dbtype) || "double".equals(dbtype) || "BigDecimal".equals(dbtype) || "Integer".equals(dbtype);
    }

    public static String initMybatisValueWithJdbcType(String dataBase, OnlCgformField item, JSONObject json, Map<String, Object> params) {
        String dbType = item.getDbType();
        String field = item.getDbFieldName();
        String pageType = item.getFieldShowType();
        if ("int".equals(dbType)) {
            params.put(field, json.getIntValue(field));
            return "#{" + field + ",jdbcType=INTEGER}";
        } else if ("double".equals(dbType)) {
            params.put(field, json.getDoubleValue(field));
            return "#{" + field + ",jdbcType=DOUBLE}";
        } else if ("BigDecimal".equals(dbType)) {
            params.put(field, new BigDecimal(json.getString(field)));
            return "#{" + field + ",jdbcType=DECIMAL}";
        } else if ("Date".equals(dbType)) {
            String fieldVal = json.getString(field);
            if ("ORACLE".equals(dataBase)) {
                if ("date".equals(pageType)) {
                    params.put(field, fieldVal.length() > 10 ? fieldVal.substring(0, 10) : fieldVal);
                    return "to_date(#{" + field + "},'yyyy-MM-dd')";
                } else {
                    params.put(field, fieldVal.length() == 10 ? json.getString(field) + " 00:00:00" : fieldVal);
                    return "to_date(#{" + field + "},'yyyy-MM-dd HH24:mi:ss')";
                }
            } else {
                params.put(field, json.getString(field));
                return "#{" + field + "}";
            }
        } else {
            params.put(field, json.getString(field));
            return "#{" + field + ",jdbcType=VARCHAR}";
        }
    }
}
